//
//  Recommend_ViewController.swift
//  AIMobileOfficeiOSApp
//
//  Created by 邓杰 on 2018/6/26.
//  Copyright © 2018年 AIMobileOffice. All rights reserved.
//

import UIKit
class Recommend_CollectionViewCell:UICollectionViewCell{
    @IBOutlet weak var recommend_imageView: UIImageView!
}

class Recommend_ViewController: UIViewController,UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout
{
    
    var images:[PPT_image]!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return images.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let reuseIdentifier="recommendCell"
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! Recommend_CollectionViewCell
        
        //cell.imageView.backgroundColor = UIColor.randomColor()
        cell.recommend_imageView.image = UIImage(named: images[indexPath.row].imagename)
        
        return cell
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        let itemSize = (collectionView.frame.width - (collectionView.contentInset.left + collectionView.contentInset.right + 10)) / 2
        return CGSize(width: itemSize, height: itemSize)
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        let mainStoryboard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let desVC=mainStoryboard.instantiateViewController(withIdentifier: "image_viewController") as! image_viewController
        desVC.picture_forImgae = UIImage(named: images[indexPath.row].imagename)
        desVC.images_s=images
        desVC.new_imageName = images[indexPath.row].imagename
        self.navigationController?.pushViewController(desVC, animated: true)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
//    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
//        return CGSize(width: collectionView.frame.width * 0.4, height:collectionView.frame.height*0.25 )
//    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
